package com.dongliu.dao;

import com.dongliu.domain.LentRecord;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface LentRecordDao {

    @Insert("insert into lentRecord values(null, #{bookId}, #{bookName}, #{username}, #{name}, #{lentDate}, null, null)")
    public int save(LentRecord lentRecord);

    @Update("update lentRecord set bookId=#{bookId}, bookName=#{bookName}, username=#{username}, name=#{name}, lentDate=#{lentDate}, returnDate=#{returnDate}, bill=#{bill} where lentId=#{lentId}")
    public int update(LentRecord lentRecord);

    @Delete("delete from lentRecord where lentId=#{lentId}")
    public int delete(Integer lentId);

    @Select("select * from lentRecord where username=#{username}")
    public List<LentRecord> getByUsername(String username);

    @Select("select * from lentRecord where lentId=#{lentId}")
    public LentRecord getByLentId(Integer lentId);

    @Select("select * from lentRecord")
    public List<LentRecord> getAll();

    @Select("select count(*) from lentRecord")
    public int getCount();

    @Select("select * from lentRecord where username=#{username}")
    public List<LentRecord> getAllByUsername(String username);

    @Select("select * from lentRecord where username=#{username} and returnDate is NULL")
    public List<LentRecord> getNotReturnByUsername(String username);
}